<?php include_once "top.php";
$user=$db->ig2_want('mae_user','openid="'.trim($_GET['openid']).'" and is_delete=0');
$shop=$db->ig2_want('mae_shop','tid='.$_GET['tid'].' and status=1');
if($user) header("location:user.php");
if($_GET['type']==1 || (time()-$_GET['regtime'])<=900){
?>
<div class="container">
	<div class="p1">
		<img class="p1bg bg" src="images/p1bg.jpg">
		<img id="subreg" src="images/p1_1.jpg">
		<input class="ipt" id="nm" type="text" name="" value="">
		<input class="ipt" id="tel" type="text" name="" value="">
		<input class="ipt" id="add" type="text" name="" value="">
		<span class="ipt" id="shop_name"><?php echo $shop['name']?></span>
		<img id="tc" src="images/cg.png">
		<img id="qr" src="images/qr.jpg">
		<img id="qr2" src="images/qr.jpg">
	</div>
</div>
<?php }else{?>
<img src="images/qcodeinvalid.jpg" width="100%"/>
<?php }?>
<script type="text/javascript">
$('#qr').click(function(){
	$('#tc,#qr').fadeOut(500);
});

$('#qr2').click(function(){
	window.location='user.php';
});

//店员管理查看
	document.getElementById("subreg").addEventListener("touchstart", touchStartsubreg, false);
	document.getElementById("subreg").addEventListener("touchend", touchEndsubreg, false);
	function touchStartsubreg(event){
		startX = event.touches[0].clientX;
		document.getElementById('subreg').src='images/p1_1_h.jpg';	
	}
	function touchEndsubreg(event){
		endX = event.changedTouches[0].clientX;
	 	document.getElementById('subreg').src='images/p1_1.jpg';
	}
	
	document.getElementById("qr").addEventListener("touchstart", touchStartqr, false);
	document.getElementById("qr").addEventListener("touchend", touchEndqr, false);
	function touchStartqr(event){
		startX = event.touches[0].clientX;
		document.getElementById('qr').src='images/qr_h.jpg';	
	}
	function touchEndqr(event){
		endX = event.changedTouches[0].clientX;
	 	document.getElementById('qr').src='images/qr.jpg';
	}
	
	document.getElementById("qr2").addEventListener("touchstart", touchStartqr2, false);
	document.getElementById("qr2").addEventListener("touchend", touchEndqr2, false);
	function touchStartqr2(event){
		startX = event.touches[0].clientX;
		document.getElementById('qr2').src='images/qr_h.jpg';	
	}
	function touchEndqr2(event){
		endX = event.changedTouches[0].clientX;
	 	document.getElementById('qr2').src='images/qr.jpg';
	}

$('#subreg').click(function(){
	var tid='<?php echo $_GET['tid']?>';
	var type='<?php echo $_GET['type']?>';
	var openid='<?php echo $_GET['openid']?>';
	var name=$('#nm').val();
	var phone=$('#tel').val();
	var address=$('#add').val();
	if(checkForm()){
		$.ajax({
			type: "GET",
			url: "ra_ajax.php?add_user=1&tid="+tid+"&type="+type+"&openid="+openid+"&name="+name+"&phone="+phone+"&address="+address,
			success: function(data){
				console.log(data);
				if(data == 'success'){
					$('#tc').attr('src','images/cg.png');
					$('#tc,#qr2').fadeIn(500);
				}
			},
			error: function(e){
				alert(e);
			}
		});
	}
});

function checkForm(){
	if(trim(document.getElementById('nm').value)==''){
		$('#tc').attr('src','images/sb_1.png');
		$('#tc,#qr').fadeIn(500);
		return false;
	}
	
	var phone=document.getElementById('tel').value;
	var myregPhone = /^(13[0-9]|14[0-9]|15[0-9]|18[0-9]|17[0-9])\d{8}$/i;
	if(trim(phone)==''){
		$('#tc').attr('src','images/sb_2.png');
		$('#tc,#qr').fadeIn(500);
		return false;
	}else{
		if(!myregPhone.test(phone)){
			$('#tc').attr('src','images/sb_3.png');
			$('#tc,#qr').fadeIn(500);
			return false;
		}
	}
	if(trim(document.getElementById('add').value)==''){
		$('#tc').attr('src','images/sb_4.png');
		$('#tc,#qr').fadeIn(500);
		return false;
	}
	return true;
}

function getWidth(){
	$('.p1,.p2,.p3,.p4,.container,.bg').width(x);
	$('.p1,.p2,.p3,.p4,.p5,.p6,.p7,.p8').css({left:0,top:0});
	//p1
	$('#subreg').width(134/p).height(76/p);
	$('#subreg').css({left:(x-134/p)/2+'px',top:1019/p+'px'});
	$('#nm').css({left:248/p+'px',top:273/p+'px',width:406/p+'px',height:64/p+'px',fontSize:24/p+'px'});
	$('#tel').css({left:248/p+'px',top:387/p+'px',width:406/p+'px',height:64/p+'px',fontSize:24/p+'px'});
	$('#add').css({left:248/p+'px',top:502/p+'px',width:406/p+'px',height:64/p+'px',fontSize:24/p+'px'});
	$('#shop_name').css({left:248/p+'px',top:616/p+'px',width:406/p+'px',lineHeight:64/p+'px',fontSize:24/p+'px',marginLeft:12/p+'px'});
	$('#tc').width(x);
	$('#tc').css({left:0,top:0});
	$('#qr,#qr2').width(134/p).height(76/p);
	$('#qr,#qr2').css({left:(x-134/p)/2+'px',top:616/p+'px'});
}
</script>
</body>
</html>